package com.xinyuan.digit.next.subscriber.db;

import com.xinyuan.digit.next.api.BaseEntity;
import com.xinyuan.digit.next.subscriber.db.provider.BaseDaoProvider;
import com.xinyuan.digit.next.subscriber.db.wapper.LambdaQueryWrapper;
import org.apache.ibatis.annotations.*;

import java.util.Collection;
import java.util.List;

/**
 * 数据库操作通用接口
 *
 * @author liuchenghui 2025/10/23
 * @version 1.0
 */
public interface BaseDao<E extends BaseEntity> {
    /**
     * 根据ID获取数据
     *
     * @param id
     * @param clazz
     * @return
     */
    @SelectProvider(type = BaseDaoProvider.class, method = "selectById")
    E selectById(Long id, Class clazz);

    /**
     * 查询单条数据
     *
     * @param wrapper
     * @return
     */
    @SelectProvider(type = BaseDaoProvider.class, method = "selectOne")
    E selectOne(@Param("collection") LambdaQueryWrapper<?> wrapper);

    /**
     * 查询所有数据
     *
     * @param wrapper
     * @return
     */
    @SelectProvider(type = BaseDaoProvider.class, method = "selectAll")
    List<E> selectAll(@Param("collection") LambdaQueryWrapper<?> wrapper);

    /**
     * 分页查询
     *
     * @param wrapper
     * @param start
     * @param length
     * @return
     */
    @SelectProvider(type = BaseDaoProvider.class, method = "selectPage")
    List<E> selectPage(@Param("collection") LambdaQueryWrapper<?> wrapper, int start, int length);

    /**
     * 查询条目数
     *
     * @param wrapper
     * @return
     */
    @SelectProvider(type = BaseDaoProvider.class, method = "selectPageCount")
    Integer selectPageCount(@Param("collection") LambdaQueryWrapper<?> wrapper);

    /**
     * 新增
     *
     * @param entity
     * @param clazz
     * @return
     */
    @InsertProvider(type = BaseDaoProvider.class, method = "insert")
    Integer insert(@Param("entity") E entity, Class clazz);

    /**
     * 根据ID更新
     *
     * @param entity
     * @param id
     * @param clazz
     * @return
     */
    @UpdateProvider(type = BaseDaoProvider.class, method = "updateById")
    Integer updateById(@Param("entity") E entity, @Param("id") Long id, Class clazz);

    /**
     * 启用禁用
     *
     * @param id
     * @param isReleased
     * @param clazz
     * @return
     */
    @UpdateProvider(type = BaseDaoProvider.class, method = "enable")
    Integer enable(Long id, boolean isReleased, Class clazz);

    /**
     * 根据ID删除
     *
     * @param id
     * @param clazz
     * @return
     */
    @UpdateProvider(type = BaseDaoProvider.class, method = "delById")
    Integer delById(Long id, Class clazz);

    /**
     * 批量删除
     *
     * @param wrapper
     * @return
     */
    @UpdateProvider(type = BaseDaoProvider.class, method = "delBatch")
    Integer delBatch(@Param("collection") LambdaQueryWrapper<?> wrapper);

    /**
     * 批量物理删除
     *
     * @param wrapper
     * @return
     */
    @DeleteProvider(type = BaseDaoProvider.class, method = "erase")
    Integer erase(@Param("collection") LambdaQueryWrapper<?> wrapper);

    /**
     * 批量新增
     *
     * @param entityCollection
     * @param clazz
     * @return
     */
    @InsertProvider(type = BaseDaoProvider.class, method = "insertBatch")
    Integer insertBatch(@Param("collection") Collection<E> entityCollection, Class clazz);
}
